﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Collections.ObjectModel;

namespace EFMockingHelpers
{
    public class MockDbSet<T> : IDbSet<T> where T : class
    {
        readonly IList<T> _container = new List<T>();

        public T Add(T entity)
        {
            _container.Add(entity);
            return entity;
        }

        public T Attach(T entity)
        {
            _container.Add(entity);
            return entity;
        }

        public TDerivedEntity Create<TDerivedEntity>() where TDerivedEntity : class, T
        {
            throw new NotImplementedException();
        }

        public T Create()
        {
            throw new NotImplementedException();
        }

        public T Find(params object[] keyValues)
        {
            throw new NotImplementedException();
        }

        public System.Collections.ObjectModel.ObservableCollection<T> Local
        {
            get
            {
                return new ObservableCollection<T>(_container);
            }
        }

        public T Remove(T entity)
        {
            _container.Remove(entity);
            return entity;
        }

        public IEnumerator<T> GetEnumerator()
        {
            return _container.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _container.GetEnumerator();
        }

        public Type ElementType
        {
            get
            {
                return typeof(T);
            }
        }

        public System.Linq.Expressions.Expression Expression
        {
            get
            {
                return _container.AsQueryable<T>().Expression;
            }
        }

        public IQueryProvider Provider
        {
            get
            {
                return _container.AsQueryable<T>().Provider;
            }
        }
    }
}
